package src;

import javax.swing.*;
import java.awt.*;

public class AdminLoginFrame extends JFrame {
    private JTextField usernameField;
    private JPasswordField passwordField;

    public AdminLoginFrame() {
        setTitle("管理员登录");
        setSize(300, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(3, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        // 用户名输入
        panel.add(new JLabel("用户名:"));
        usernameField = new JTextField();
        panel.add(usernameField);

        // 密码输入
        panel.add(new JLabel("密码:"));
        passwordField = new JPasswordField();
        panel.add(passwordField);

        // 登录按钮
        JButton loginButton = new JButton("登录");
        loginButton.addActionListener(e -> {
            // TODO: 实现登录验证逻辑
            String username = usernameField.getText();
            String password = new String(passwordField.getPassword());
            
            if (validateAdmin(username, password)) {
                new AdminMainFrame().setVisible(true);
                this.dispose();
            } else {
                JOptionPane.showMessageDialog(this, "用户名或密码错误！", "错误", JOptionPane.ERROR_MESSAGE);
            }
        });

        // 返回按钮
        JButton backButton = new JButton("返回");
        backButton.addActionListener(e -> {
            new MainFrame().setVisible(true);
            this.dispose();
        });

        JPanel buttonPanel = new JPanel();
        buttonPanel.add(loginButton);
        buttonPanel.add(backButton);
        panel.add(buttonPanel);

        add(panel);
    }

    private boolean validateAdmin(String username, String password) {
        // TODO: 实现实际的管理员验证逻辑
        return "admin".equals(username) && "admin123".equals(password);
    }
} 